<html>
<head><meta charset="utf-8"><title>Deadlines or timeouts · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html">Deadlines or timeouts</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="200509824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200509824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200509824">(Jun 11 2020 at 06:38)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> IIUC parking_lot is implemented internally in terms of deadlines, not timeouts. Is there any rationale for choosing one over the other? Could you point to any references?</p>



<a name="200512076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200512076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200512076">(Jun 11 2020 at 07:17)</a>:</h4>
<p>Timeout don't deal with interruptions well. For example if a signal handler executes while you were blocked waiting for a mutex.</p>



<a name="200512147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200512147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200512147">(Jun 11 2020 at 07:18)</a>:</h4>
<p>Here's a general discussion of intervals vs. deadlines, it might help: <a href="https://davmac.wordpress.com/2016/08/12/posix-timer-apis-are-borked/">https://davmac.wordpress.com/2016/08/12/posix-timer-apis-are-borked/</a>. I think one of the concerns POSIX has against interval timers is that appears to be no non-racy way to make a deadline timer using an interval one. You can look at the current time and compute the difference, but the clock might change in the meanwhile.</p>



<a name="200512280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200512280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200512280">(Jun 11 2020 at 07:20)</a>:</h4>
<p>That's a separate issue of CLOCK_MONOTONIC vs CLOCK_REALTIME. parking_lot uses CLOCK_MONOTONIC everywhere (unless not supported by a particular platform).</p>



<a name="200514825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200514825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200514825">(Jun 11 2020 at 08:00)</a>:</h4>
<p>Just to be clear, the problem with interruptions is something like this: you issue a syscall with a specific timeout, it's interrupted and therefore returns early. now you don't know how long to set the timeout when reissuing the syscall?</p>



<a name="200519045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200519045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200519045">(Jun 11 2020 at 08:50)</a>:</h4>
<p>Yes, essentially.</p>



<a name="200519077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200519077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200519077">(Jun 11 2020 at 08:50)</a>:</h4>
<p>The only way to handle that reliably is to convert the timeout to a deadline and then use that.</p>



<a name="200523086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Deadlines%20or%20timeouts/near/200523086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Deadlines.20or.20timeouts.html#200523086">(Jun 11 2020 at 09:38)</a>:</h4>
<p>Windows meanwhile won't cut your sleep short due to interruptions, but it will round your duration to the nearest scheduler tick in either direction, meaning your sleep can still end early by several milliseconds!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>